<?php

namespace App\Console\Commands;

use App\Customer;
use App\Lead;
use Illuminate\Console\Command;

class CustomerFilter extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'customer:Filter';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
      Customer::whereOwnerUserId(	39)
  /*  ->where('deal_time','<=',time()-60*86400)
     ->where('is_lock','!=',1)*/
    ->chunkById(100,function ($customers){

        foreach($customers as $item){
            $this->info($item->customer_id);
            $lead=Lead::whereCustomerId($item->customer_id)->first();
            if($lead){
                 //   $this->info($lead->leads_id);
                    $newModel=$lead->replicate();
                    $newModel->owner_user_id=15;
                    $newModel->create_user_id=1;
                    $newModel->is_transform=0;
                    $newModel->customer_id=0;
                    $newModel->next_time=0;
                    $newModel->follow='待跟进';
                    $newModel->remark=$item->content;
                    $newModel->create_time=time();
                    $newModel->update_time=time();
                    $newModel->project_id=9;
                    $newModel->status='潜在客户';
                    $newModel->save();
                    $this->info($newModel->leads_id);
            }
        }
    });



    }
}
